/* const imgSrc = "https://cn.bing.com/images/search?view=detailV2&ccid=TuITIomu&id=7332E9F56DD01B46DC605B5C76AE9CE2745850A2&thid=OIP.TuITIomuqFDayqkGArIBNAHaE9&mediaurl=https%3a%2f%2ftse1-mm.cn.bing.net%2fth%2fid%2fR-C.4ee2132289aea850dacaa90602b20134%3frik%3dolBYdOKcrnZcWw%26riu%3dhttp%253a%252f%252fpic6.huitu.com%252fres%252f20121201%252f42146_20121201215256355386_1.jpg%26ehk%3deO0mpPLWcThKMSaBoB%252b7NK5ltaWLK5KiMm6jgBF34S4%253d%26risl%3d%26pid%3dImgRaw%26r%3d0&exph=602&expw=900&q=%e8%82%89%e7%89%87&simid=608038331288728489&FORM=IRPRST&ck=4EFAE64E503BA9B243556B7D736CBD9E&selectedIndex=1&ajaxhist=0&ajaxserp=0"
// 基本使用函数
function uploadImages(imgSrc, callback){
    const imgNode = document.createElement("img")
    imgNode.src = imgSrc
    imgNode.alt = "我是一张图片"
    imgNode.style = "width:200px;height:200px;"
    imgNode.onload = ()=>callback(null, imgNode)
    imgNode.onerror = (err)=>callback(err)
}
// 回调函数版本
uploadImages(imgSrc, function(err,...values){
    if(err){
        console.log("error")
        return
    }
    console.log("success....",values)
})
// 改造成promise版本
    // 返回一个promise可以then
const uploadImagesPromise = function uploadImagesPromise(imgSrc){
    return new Promise((resolve, reject)=>{
        uploadImages(imgSrc, (err, ...values)=>{
            if(err){
                reject(err)
                return
            }
            resolve(values)
        })
    })
}
uploadImagesPromise(imgSrc).then(res => {
    console.log(res)
})
.catch(err => {
    console.log(err)
})
// 通用函数promisify ，将callback改装promise 
 
    // original是最后一个参数为回调函数的函数
 
function promisify(original){
    return function(...args){
        return new Promise((resolve, reject)=>{
            args.push((err, ...values)=>{
                if(err){
                    reject(err)
                    return
                }
                resolve(values)
            })
            Reflect.apply(original,this,args)
        })
    }
} 
const loadImagePromise = promisify(uploadImages)
async function load(){
    try{
        const res = await loadImagePromise(imgSrc)
        console.log(res)
    }catch(err){
        console.log(err)
    }
} */
new Promise(() => {
    console.log(1111112)
    throw new Error('message')
    console.log(123)
}).catch(err => {
    console.log(err)
})
console.log("我比错我")


// inital里面传入一个回调函数
setTimeout(() => {

})
function promisify(inital) {
    return function (...args) {
        return new Promise((resolve, reject) => {
            args.push((err, ...values) => {
                if (err) {
                    reject(err)
                    return
                }
                resolve(...values)
            })
            Reflect.apply(inital, this, args)
        })
    }
}